/* eslint valid-jsdoc: "off" */

"use strict";

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = (appInfo) => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  const config = (exports = {});

  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + "_1615169687728_1262";

  // add your middleware config here
  config.middleware = ['showUrl'];

  // add your user config here
  const userConfig = {
    // myAppName: 'egg',
    auth:{
      whitelist: ["/login", "/reg", "/test"],
      body2jsonList: ["where", "orders"],
      operations: [
        { path: "/get", auth: "SELECT", pointer:0},
        { path: "/delete", auth: "DELETE", pointer:1 },
        { path: "/add", auth: "INSERT", pointer:2 },
        { path: "/edit", auth: "UPDATE", pointer:3 },
        { path: "/tree", auth: "TREE", pointer:4 },
        { path: "/excute", auth: "EXCUTE", pointer:5 },
        { path: "/upload", auth: "UPLOAD", pointer:6 },
        { path: "/download", auth: "DOWNLOAD", pointer:7 },
        { path: "/preview", auth: "PREVIEW", pointer:8 },
        { path: "/mq/send", auth: "MQ_SEND", pointer:9 },
      ],
      public:['EXCUTE','UPLOAD','DOWNLOAD','PREVIEW','MQ_SEND']
    }
  };

  const mysql = {
    clients: {
      meta: {
        host: "localhost",
        port: "3306",
        user: "root",
        password: "123456",
        database: "meta",
        // debug: true,
      },
      todo: {
        host: "localhost",
        port: "3306",
        user: "root",
        password: "123456",
        database: "todo",
        // debug: true,
      },
    },
    defaultLimit: 20,
    defaultOrders: [["id", "desc"]],
  };
  config.mysql = mysql;

  //jwt配置
  config.jwt = {
    secret: "aFX6SzN7JAAccZKOC6XiMl3NGvSS8lEw",
  };

  //跨域配置
  config.security = {
    csrf: {
      enable: false,
      ignoreJSON: true,
    },
    domainWhiteList: ["http://localhost:8080"],
  };

  //跨域配置
  config.cors = {
    origin: "*",
    allowMethods: "GET,HEAD,PUT,POST,DELETE,PATH",
  };

  //emqtt配置
  config.emqtt = {
    client: {
      host: "mqtt://127.0.0.1",
      username: "admin",
      password: "admin",
      clientId: "complex",
      options: {
        keepalive: 60,
        protocolId: "MQTT",
        protocolVersion: 4,
        clean: true,
        reconnectPeriod: 1000,
        connectTimeout: 30 * 1000,
        rejectUnauthorized: false,
      },
      // msgMiddleware: [ 'msg2json' ],
    },
  };

  return {
    ...config,
    ...userConfig,
  };
};
